package com.real8.romemp.client.ui;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.SpanElement;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Widget;

public class PiracyViewImpl extends Composite implements PiracyView {

	private static PiracyViewImplUiBinder uiBinder = GWT
			.create(PiracyViewImplUiBinder.class);

	interface PiracyViewImplUiBinder extends UiBinder<Widget, PiracyViewImpl> {
	}

	private Presenter presenter;

	@UiField
	HTMLPanel piratesAttackPanel;

	@UiField
	HTMLPanel lossesPanel;
	@UiField
	SpanElement localMerchantShipsLostSpan;
	@UiField
	SpanElement overseeMerchantShipsLostSpan;

	@UiField
	Button continueButton;

	public PiracyViewImpl() {
		initWidget(uiBinder.createAndBindUi(this));
	}

	@Override
	public void setPresenter(Presenter aPresenter) {
		this.presenter = aPresenter;
	}

	@Override
	public void hideAll() {
		piratesAttackPanel.setVisible(false);
		lossesPanel.setVisible(false);
		continueButton.setVisible(false);
	}

	@Override
	public void showPiratesAttack() {
		piratesAttackPanel.setVisible(true);
	}

	@Override
	public void showLosses(int localMerchantShipsLost,
			int overseeMerchantShipsLost) {
		localMerchantShipsLostSpan.setInnerText("" + localMerchantShipsLost);
		overseeMerchantShipsLostSpan
				.setInnerText("" + overseeMerchantShipsLost);

		lossesPanel.setVisible(true);
	}

	@Override
	public void showContinue() {
		continueButton.setVisible(true);
	}

	@UiHandler("continueButton")
	void onContinueButtonClicked(ClickEvent e) {
		if (presenter != null) {
			presenter.onContinue();
		}
	}
}
